//
//  ErrorView.m
//  League
//
//  Created by JackChen on 2018/2/19.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "ErrorView.h"

@implementation ErrorView

- (instancetype)initWithFrame:(CGRect)frame ErrorMessage:(NSString *)message
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        bgView.backgroundColor = [UIColor blackColor];
        bgView.alpha = 0.7;
        [self addSubview:bgView];
        
        UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(20, 0, kScreenWidth - 40, 150)];
        contentView.center = bgView.center;
        contentView.layer.cornerRadius = 6;
        contentView.layer.masksToBounds = YES;
        contentView.backgroundColor = [UIColor whiteColor];
        [self addSubview:contentView];
        
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, contentView.frame.size.width, 50)];
        titleLabel.text = @"Errors";
        titleLabel.textColor = sRGBColor(80, 80, 80);
        titleLabel.font = [UIFont boldSystemFontOfSize:20];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [contentView addSubview:titleLabel];
        
        UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(titleLabel.frame), contentView.frame.size.width - 40, 100)];
        messageLabel.text = message;
        messageLabel.textColor = sRGBColor(80, 80, 80);
        messageLabel.font = [UIFont systemFontOfSize:18];
        messageLabel.lineBreakMode = NSLineBreakByCharWrapping;
        messageLabel.numberOfLines = 0;
        [contentView addSubview:messageLabel];
        [messageLabel sizeToFit];
        messageLabel.frame = CGRectMake(20, CGRectGetMaxY(titleLabel.frame), contentView.frame.size.width - 40, messageLabel.frame.size.height);
        messageLabel.textAlignment = NSTextAlignmentCenter;
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(messageLabel.frame) + 15, contentView.frame.size.width, 1)];
        lineView.backgroundColor = sRGBColor(225, 225, 225);
        [contentView addSubview:lineView];
        
        UIButton *sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
        sureButton.frame = CGRectMake(0, CGRectGetMaxY(lineView.frame), contentView.frame.size.width, 44);
        [sureButton setTitle:@"确定" forState:UIControlStateNormal];
        sureButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [sureButton setTitleColor:sRGBColor(158, 158, 158) forState:UIControlStateNormal];
        [sureButton addTarget:self action:@selector(sureAction:) forControlEvents:UIControlEventTouchUpInside];
        sureButton.userInteractionEnabled = YES;
        [contentView addSubview:sureButton];
        contentView.bounds = CGRectMake(0, 0, contentView.frame.size.width, CGRectGetMaxY(sureButton.frame));
    }
    return self;
}

- (void)sureAction:(UIButton *)sender {
    [self removeFromSuperview];
}

@end
